<!----------------------------PHP---------------------------------------->

<?php

if(isset($selectedAppointment))
{
	//print_r($selectedAppointment);
	
}

if(isset($profile))
{
	//print_r($profile);
}


$found=false;

echo "<script>var procList = new Array(); </script>";
echo "<script>var procItemList = new Array(); </script>";
echo "<script>var invItemList = new Array(); </script>";
echo "<script>var aptList = new Array(); </script>";
echo "<script>var procAptList = new Array(); </script>";
echo "<script>var selectedProcList = new Array();</script>";
echo "<script>var selectedProcNameList = new Array();</script>";
echo "<script>var estTime;</script>";
echo "<script>var readOnly=false;</script>";


$numbOfDay = 7;
$openingHours = 12;
$openingAt = 9;
$closingAt = $openingAt+$openingHours;
$slots = $openingHours * 4;
$minuteSlot = array("00","15","30","45");
$aptIsSelected = false;
$timeArrayInInteger = array();
$colorList = array("Red","Gold","Blue","Green","Purple");
$currentColor=0;

if(isset($allAppointments))
{
	//print_r($allAppointments);
	
}


if(isset($procedures))
{
	//print_r($procedures);	
	
	//$proc1 = 'foo';
	//$proc2 = 'goo';
	//$proc3 = 'hoo';
	
	//echo "<script>procList.push(['".$proc1."']);</script>";   WORKS!
	
	//echo "<script>procList.push(['".$proc1."','".$proc2."','".$proc3."']);</script>"; //VERY IMPORTANT TEMPLATE!!!
	
	//echo "<script>procList.push(['".$procedures[0]->getProcedureId()."','".$procedures[0]->getName()."','".$procedures[0]->getDuration()."']);</script>"; // VERY IMPORTANT TOO !!!
	
	
	foreach($procedures as $proc)
	{
		echo "<script>procList.push(['".$proc->getProcedureId()."','".$proc->getName()."','".$proc->getDuration()."']);</script>";
	}
}


if(isset($selectedAppointment) && isset($proceduresByAppointment) && $selectedAppointment != "")
{
//print_r($proceduresByAppointment);
//print_r($selectedAppointment);

	$aptIsSelected = true;
	
	foreach($proceduresByAppointment as $procByApt)
	{
		echo "<script>selectedProcList.push(['".$procByApt->getProcedureId()."']);</script>";
		
		foreach($procedures as $proc)
		{
			if($proc->getProcedureId() == $procByApt-> getProcedureId())
			{
				echo "<script>selectedProcNameList.push(['".$proc->getName()."']);</script>";
			}
		}
			
			
		//print_r($procByApt);
	}
		
		echo "<script>alert(selectedProcList)</script>";
		echo "<script>alert(selectedProcNameList)</script>";
		
	echo "<script>readOnly = true;</script>";
		
}


if(isset($person) && isset($profile)) //&& isset($cars) && isset($notifications))
{
			$found=true;
			//print_r($person);
			//print_r($profile);
			//print_r($cars);
			//print_r($notifications);		
			
			echo "<script>var clientId = ".$profile->getProfileId()."</script>"; 			
}

/*if(isset($carIndex))
{
	echo $carIndex;
}
else
{
	echo "No Index.";
}*/


if(isset($allProceduresItems))
{
	//print_r($allProceduresItems);	
	
	foreach($allProceduresItems as $procItem)
	{
		echo "<script>procItemList.push(['".$procItem->getProcedureId()."','".$procItem->getInventoryId()."','".$procItem->getQuantityNeeded()."']);</script>";
	}
}

if(isset($inventoryItems))
{
	//print_r($inventoryItems);	
	
	foreach($inventoryItems as $invItem)
	{
		echo "<script>invItemList.push(['".$invItem->getInventoryId()."','".$invItem->getProductName()."','".$invItem->getProductDescription()."','".$invItem->getProductQuantity()."']);</script>";
	}
	
}

if(isset($appointments))
{
	foreach($appointments as $appointment)
	{
		echo "<script>aptList.push(['".$appointment->getAppointmentId()."','".$appointment->getDate()."','".$appointment->getStartTime()."','".$appointment->getEndTime()."','".$appointment->getTotalEstimateTime()."','".$appointment->getStatus()."','".$appointment->getProfileId()."','".$appointment->getCarId()."']);</script>";
	}
	
	
}

if(isset($proceduresByAppointment))
{
	foreach($proceduresByAppointment as $procByApt)
	{
		echo "<script>procAptList.push(['".$procByApt->getAppointmentId()."','".$procByApt->getProcedureId()."'])</script>";
	}
}

function getItemsNamesAndQtyNeeded($procByApt,$allProceduresItems,$inventoryItems)
{
	$itemsNameList="";
	$itemsQtyList="";
	$itemDetails = array();
	
	foreach($allProceduresItems as $procItem)
	{
		if($procByApt->getProcedureId() == $procItem->getProcedureId())
		{
			foreach($inventoryItems as $item)
			{
				if($procItem->getInventoryId() == $item->getInventoryId())
				{
					$itemsNameList .= $item->getProductName() . "<br>";
				}
			}
			
			$itemsQtyList .= $procItem->getQuantityNeeded() . "<br>";
		}
	}

	$itemDetails[0]=$itemsNameList;
	$itemDetails[1]=$itemsQtyList;
	
	return($itemDetails);

}

function displayTable($proceduresByAppointment,$procedures,$allProceduresItems,$inventoryItems)
{
	//$test = "<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>";
	
	//return $test;
	
	$tHeader="<table width='100%' style='border:0px solid orange'>";	
	$tBody="";
	$tFooter="</table>";
	$estTime=0;
	
	$index = 0;
	
	foreach($proceduresByAppointment as $procByApt)
	{
		$tBody .= "<tr onclick='selectProcInTable(" . $index . ")' disabled>";
		$index++;
		
		foreach($procedures as $proc)
		{		
			if($procByApt->getProcedureId() == $proc->getProcedureId())
			{
				$procName = $proc->getName();
				$procDuration = $proc->getDuration();
				$estTime += $procDuration;
				
				$procItems = array();
				$procItems = getItemsNamesAndQtyNeeded($procByApt,$allProceduresItems,$inventoryItems);	
			}
		}
		
		$tBody .= "<td width='40%'>" . $procName . "</td><td width='40%'>" . $procItems[0] . "</td><td width='10%'>" . $procItems[1] . "</td><td width='10%'>" . $procDuration . "</td>";
		$tBody .= "</tr>";
	}
	
	return($tHeader.$tBody.$tFooter);
	
}

function getEstTime($estTime)
{

	$hour = (int)($estTime/60);
	
	$minute = $estTime%60;
	
	$time="";
	
	if($hour !=0)
	{
		$time = $hour . " Hour(s) " . $minute . " Minute(s)";
	}
	else
	{
		$time = $minute . " Minutes";
	}
		
	return $time;
}


//$today = $date;
//$md=strtotime($today);
//$tomorow = date('Y-m-d', mktime(date('h',$md),date('i',$md), date('s',$md), date('m',$md),date('d',$md)+1, date('Y',$md)));

//echo $date;

//$currentCalendarDate = date("Y-m-d");/////////////////////////remove when controler passes a date
$monday = strtotime($date);
$tuesday =mktime(date('h',$monday),date('i',$monday), date('s',$monday), date('m',$monday)+0,date('d',$monday)+1, date('Y',$monday)+0);
$wednesday =mktime(date('h',$tuesday),date('i',$tuesday), date('s',$tuesday), date('m',$tuesday)+0,date('d',$tuesday)+1, date('Y',$tuesday)+0);
$thursday =mktime(date('h',$wednesday),date('i',$wednesday), date('s',$wednesday), date('m',$wednesday)+0,date('d',$wednesday)+1, date('Y',$wednesday)+0);
$friday =mktime(date('h',$thursday),date('i',$thursday), date('s',$thursday), date('m',$thursday)+0,date('d',$thursday)+1, date('Y',$thursday)+0);
$saturday =mktime(date('h',$friday),date('i',$friday), date('s',$friday), date('m',$friday)+0,date('d',$friday)+1, date('Y',$friday)+0);
$sunday =mktime(date('h',$saturday),date('i',$saturday), date('s',$saturday), date('m',$saturday)+0,date('d',$saturday)+1, date('Y',$saturday)+0);
$dateOfThisWeek = array(date("Y-m-d",$monday),date("Y-m-d",$tuesday),date("Y-m-d",$wednesday),date("Y-m-d",$thursday),date("Y-m-d",$friday),date("Y-m-d",$saturday),date("Y-m-d",$sunday));





function isChecked($note,$notifications)
{
	
	$checked = false;

		foreach($notifications as $a)
		{
			if($a->getNotificationId() == $note)
			{
				$checked = true;
			}
				
		}


	return $checked;
}


?>


<!--------------------------------Javascript------------------------------>
<script>

//alert(procList);
//alert(procItemList);
//alert(invItemList);
//alert(aptList);
//alert(procAptList);
//alert(selectedProcList);

var selectedCarIndex;
var selectedProcIndex;

var selectedProcTableIndex;

var appointmentStatus = "open";


function searchProfile()
{
	document.getElementById("appointmentAction").value="search";
	document.appointmentForm.submit();
}

function selectCar()
{
	var carSelection = document.getElementById("carSelection");
	selectedCarIndex = carSelection.options[carSelection.selectedIndex].value;
	
	//alert(selectedCarIndex);
	return selectedCarIndex;
	
}

function selectProcedure()
{
	var procSelection = document.getElementById("procedureSelection");
	selectedProcIndex = procSelection.options[procSelection.selectedIndex].value;
	
	//alert(selectedProcIndex);
	
}

function saveAppointment()
{
	var startHourSelection = document.getElementById("start_hour");
	var endHourSelection = document.getElementById("end_hour");
	var startMinuteSelection = document.getElementById("start_min");
	var endMinuteSelection = document.getElementById("end_min");
		

		document.getElementById("apt_selectedCarId").value = selectCar();
		document.getElementById("apt_selectedProcList").value = selectedProcList;
		document.getElementById("apt_selectedProcNameList").value = selectedProcNameList;
		
		alert(selectedProcList);
		alert(selectedProcNameList);
		
		//alert(document.getElementById("apt_selectedProcNameList").value);
		
		document.getElementById("apt_appointmentDate").value = document.getElementById("appointmentDate").value;
		
		var startTime = ((startHourSelection.options[startHourSelection.selectedIndex].value) * 100) + ((startMinuteSelection.options[startMinuteSelection.selectedIndex].value)*15);
		var endTime = ((endHourSelection.options[endHourSelection.selectedIndex].value)*100) + ((endMinuteSelection.options[endMinuteSelection.selectedIndex].value)*15);
		
		document.getElementById("apt_startTime").value = startTime;	
		document.getElementById("apt_endTime").value = endTime;
		
		document.getElementById("apt_status").value = appointmentStatus;
		document.getElementById("apt_clientId").value = clientId;
		document.getElementById("apt_estTime").value = estTime;
		
		
		//alert(selectedCarIndex);
		//alert(selectedProcList);
		//alert(document.getElementById("appointmentDate").value);
		//alert(startTime);
		//alert(endTime);
		//alert(appointmentStatus);
		//alert(clientId);
		//alert(estTime);
		
		//alert(document.getElementById("appointmentAction").value);
		document.appointmentForm.submit();
}

function prepareCreate()
{
	//document.getElementById("carSelection").selectedIndex = "-1";
	selectedProcList=[];
	selectedProcNameList=[];
	
	createProcTable();
	document.getElementById("appointmentDate").value="";
	
	document.getElementById("start_hour").selectedIndex = "0";
	document.getElementById("start_min").selectedIndex = "0";
	document.getElementById("end_hour").selectedIndex = "0";
	document.getElementById("end_min").selectedIndex = "0";
	
	document.getElementById("a_id").value="";
	
	
	
}

function createAppointment()
{
	if(document.getElementById("appointmentAction").value=="")
	{
		prepareCreate()
		document.getElementById("createAppointmentBtn").value="Cancel Create";
		document.getElementById("appointmentAction").value="create";
		document.getElementById("carSelection").disabled = false;
		document.getElementById("procedureSelection").disabled = false;
		document.getElementById("saveAppointmentBtn").disabled = false;
		document.getElementById("editAppointmentBtn").disabled = true;
		document.getElementById("deleteAppointmentBtn").disabled = true;
		document.getElementById("appointmentDate").disabled = false;
		document.getElementById("start_hour").disabled = false;
		document.getElementById("start_min").disabled = false;
		document.getElementById("end_hour").disabled = false;
		document.getElementById("end_min").disabled = false;
		document.getElementById("plus").disabled = false;
		document.getElementById("minus").disabled = false;
		readOnly = false;
	}
	else if(document.getElementById("appointmentAction").value=="create")
	{
		document.getElementById("appointmentAction").value="search";
		document.appointmentForm.submit();
	}
}

function addTask()
{
	if(selectedProcIndex>0)
	{
		selectedProcList.push(selectedProcIndex);
		selectedProcNameList.push((procList[document.getElementById("procedureSelection").selectedIndex-1])[1]);
	}
	
	alert(selectedProcList);
	alert(selectedProcNameList);

	createProcTable();

}

function removeTask()
{
	selectedProcList.splice(selectedProcTableIndex,1);
	selectedProcNameList.splice(selectedProcTableIndex,1);
	selectedProcTableIndex = null;
	document.getElementById("minus").disabled = true;
	
	alert(selectedProcList);
	alert(selectedProcNameList);
	
	createProcTable();
	
}


function createProcTable()
{
	var tHeader="<table width='100%' style='border:0px solid orange'>";	
	var tBody="";
	var tFooter="</table>";
	estTime=0;
	
	
	for(var x=0; x<selectedProcList.length; x++)
	{
		tBody += "<tr id='" + x + "' onclick='selectProcInTable(" + x + ")'>";
		

		for(var y=0; y<procList.length; y++)
		{
			if(selectedProcList[x] == procList[y][0])
			{
				var procName = procList[y][1];
				var procDuration = procList[y][2];
				estTime += parseInt(procDuration);
				
				
				
				var procItems = new Array();
				procItems = getItemsNamesAndQtyNeeded(selectedProcList[x]);
				
			}
		}
		
		tBody += "<td width='40%'>" + procName + "</td><td width='40%'>" + procItems[0] + "</td><td width='10%'>" + procItems[1] + "</td><td width='10%'>" + procDuration + "</td>";
		tBody += "</tr>";
		
	}
	
	
	
	var hour = Math.floor(estTime/60);
	
	var minute = estTime%60;
	
	if(hour !=0)
	{document.getElementById("estTime").innerHTML = hour + " Hour(s) " + minute + " Minute(s)";}
	else if(hour==0 && estTime != 0)
	{document.getElementById("estTime").innerHTML = minute + "Minutes";}
	else
	{document.getElementById("estTime").innerHTML = "N/A";}
	

	document.getElementById("procTable").innerHTML = tHeader + tBody + tFooter;
	
	
	document.getElementById("plus").disabled = false;

}

function getItemsNamesAndQtyNeeded(selected)
{
	var itemsNameList="";
	var itemsQtyList="";
	var itemDetails = new Array();
	
	
	
	for(var j=0; j<procItemList.length; j++)
	{
		if(selected == procItemList[j][0])
		{
		
			for(var k=0; k<invItemList.length; k++)
			{
				if(procItemList[j][1] == invItemList[k][0])
				{
					itemsNameList += invItemList[k][1] + "<br>";
				}
				
			}
			
			itemsQtyList += procItemList[j][2] + "<br>";
		}
	}

	//alert(itemsQtyList);
	//alert(itemsNameList);

	itemDetails.push(itemsNameList);
	itemDetails.push(itemsQtyList);
	
	return(itemDetails);

}

function selectProcInTable(selectedIndex)
{

//alert(selectedIndex);
//alert(selectedProcTableIndex);
if(readOnly == false)
{
	if(selectedProcTableIndex == null)
	{
		document.getElementById(selectedIndex).style.backgroundColor = "yellow";
		selectedProcTableIndex = selectedIndex;
		document.getElementById("minus").disabled = false;
		document.getElementById("plus").disabled = true;
	}
	
	else if(selectedProcTableIndex == selectedIndex)
	{
		document.getElementById(selectedIndex).style.backgroundColor = "gray";
		selectedProcTableIndex = null;
		document.getElementById("minus").disabled = true;
		document.getElementById("plus").disabled = false;
	}
}
	
}

function selectAppointment(selected)
{
	//alert(selected);
	document.getElementById("appointmentAction").value = "setSelectedAppointment";
	document.getElementById("selectedAppointmentId").value = selected;
	document.appointmentForm.submit();
}



/*function selectAppointmentFromCalendar(selected)
{
	//alert(selected);
	document.getElementById("appointmentAction").value = "setSelectedAppointment";
	document.getElementById("selectedAppointmentId").value = selected;
	document.appointmentForm.submit();
}*/

function editAppointment()
{
	if(document.getElementById("appointmentAction").value != "edit")
	{	
		document.getElementById("editAppointmentBtn").value="Cancel Edit";
		document.getElementById("createAppointmentBtn").disabled = true;
		document.getElementById("appointmentAction").value = "edit";
		document.getElementById("carSelection").disabled = false;
		document.getElementById("procedureSelection").disabled = false;
		document.getElementById("saveAppointmentBtn").disabled = false;
		document.getElementById("appointmentDate").disabled = false;
		document.getElementById("start_hour").disabled = false;
		document.getElementById("start_min").disabled = false;
		document.getElementById("end_hour").disabled = false;
		document.getElementById("end_min").disabled = false;
		document.getElementById("plus").disabled = false;
		document.getElementById("minus").disabled = false;
		readOnly = false;
	}
	else if(document.getElementById("appointmentAction").value == "edit")
	{
		document.getElementById("appointmentAction").value = "setSelectedAppointment";
		document.appointmentForm.submit();
	}
}

function deleteAppointment()
{
	document.getElementById("appointmentAction").value = "delete";
	document.appointmentForm.submit();
}

function endAppointment()
{
	document.getElementById("appointmentAction").value = "end";
	saveAppointment();
}

function nextWeek()
{
	document.getElementById("appointmentAction").value="showNextWeek";
	document.appointmentForm.submit();
	
}

function lastWeek()
{
	document.getElementById("appointmentAction").value="showLastWeek";
	document.appointmentForm.submit();
}


</script>
<!------------------------------------------------------------------------>
<td> 



<form name="appointmentForm" action="#" method="post">
	<table class="content">
	
	<tr>	
		<td colspan="3">
			Appointment:   
			<input type="text" id="searchAppointmentInput" name="searchAppointmentInput" placeholder="Enter phone number">  
			<input type="button" id="searchAppointmentBtn" onclick="searchProfile()" value="Search"> 
			<input type="button" id="deleteAppointmentBtn" value="Delete Appointment" class="right" onclick="deleteAppointment()" <?php if($aptIsSelected){echo "enabled";}else{echo "disabled";}?>>
			<input type="button" id="editAppointmentBtn" onclick="editAppointment()" value="Edit Appointment" class="right" <?php if($aptIsSelected){echo "enabled";}else{echo "disabled";}?>>
			<input type="button" id="saveAppointmentBtn" onclick="saveAppointment()" value="Save Appointment" class="right" disabled>
			<input type="button" id="createAppointmentBtn" value="Create Appointment" onclick="createAppointment()" class="right" disabled>
			
			<?php if($found){echo "<script>document.getElementById('createAppointmentBtn').disabled = false;</script>";} ?>	
			
			<input type="hidden" id="appointmentAction" name="appointmentAction" value="">
			<input type="hidden" id="currentDate" name="currentDate" value="<?php echo $date;?>">
			<input type="hidden" id="searchInput" name="searchInput" value="<?php if(isset($person)){ echo $person->getHomePhoneNumber();}?>">
			
			<input type="hidden" id="apt_selectedCarId" name="apt_selectedCarId" value="">
			<input type="hidden" id="apt_selectedProcList" name="apt_selectedProcList" value="">
			<input type="hidden" id="apt_selectedProcNameList" name="apt_selectedProcNameList" value="">
			<input type="hidden" id="apt_appointmentDate" name="apt_appointmentDate" value="">
			<input type="hidden" id="apt_startTime" name="apt_startTime" value="">
			<input type="hidden" id="apt_endTime" name="apt_endTime" value="">
			<input type="hidden" id="apt_clientId" name="apt_clientId" value="">
			<input type="hidden" id="apt_estTime" name="apt_estTime" value="">
			<input type="hidden" id="apt_status" name="apt_status" value="">
			<input type="hidden" id="selectedAppointmentId" name="selectedAppointmentId" value="<?php if($aptIsSelected){echo $selectedAppointment->getAppointmentId();} ?>">
			
			
			
			
			<br>
			
		</td>				
	</tr>
	
	<tr>
		<td width="30%">
			<table height="100%">
	
							<tr>
								<td><div class="round2">
									<table style="width:100%; border:0px solid black; height:10%">
										<tr>
											<td>Appointment Id:</td>
											<td><input type="text" name="a_id" id="a_id" value="<?php if($aptIsSelected){echo $selectedAppointment->getAppointmentId();}?>" disabled></td>
										</tr>
										<tr>
											<td>Client Id:</td>     
											<td><input type="text" name="c_id" id="c_id" value="<?php if($found){echo $profile->getProfileId();} ?>" disabled></td>
										</tr>
										<tr>
											<td>Gender:</td>
											<td>
											<input type="radio" name="c_sex" id="c_sex_male" value="Male" disabled>Male
											<input type="radio" name="c_sex" id="c_sex_female" value="Female" disabled>Female
											</td>
										</tr>
										<?php
											if($found)
											{
												if($person->getGender()=="M")
												{
													echo "<script>document.getElementById('c_sex_male').checked=true;</script>";
																	
												}
												else
												{
													echo "<script>document.getElementById('c_sex_female').checked=true;</script>";
												}
											}
										?>
										<tr>
											<td>First Name:</td>    
											<td><input type="text" id="c_fname" name="c_fname" value="<?php if($found){echo $person->getFirstName();} ?>" disabled></td>
										</tr>
										<tr>
											<td>Last Name:</td>     
											<td><input type="text" id="c_lname" name="c_lname"  value="<?php if($found){echo $person->getLastName();} ?>" disabled></td>
										</tr>
										<tr>
											<td>Home Phone:</td>    
											<td><input type="text" id="c_hphone" name="c_hphone" value="<?php if($found){echo $person->getHomePhoneNumber();} ?>" disabled></td>
										</tr>
										<tr>
											<td>Cell Phone:</td>    
											<td><input type="text" id="c_cphone" name="c_cphone" value="<?php if($found){echo $person->getCellPhoneNumber();} ?>" disabled></td>
										</tr>
										<tr>
											<td>Email:</td>         
											<td><input type="text" id="c_email" name="c_email" value="<?php if($found){echo $person->getEMail();} ?>" disabled></td>
										</tr>
										<tr>
											<td>Appointment Reminder</td>      
											<td><input type="radio" id="note1_yes" value="Yes" name="note1" <?php if($found){if(isChecked(1,$notifications)){echo "checked";}} ?> disabled>Yes<input type="radio" id="note1_no" value="No" name="note1" <?php if($found){if(!isChecked(1,$notifications)){echo "checked";}}else{echo "checked";} ?> disabled>No</td>
										</tr>
									</table></div>	
								</td>
							</tr>
							
							<tr>
								<td><br><div class="round2">
									<table style="border:0px solid black; width:100%; height:90%">
										<tr>
											<td width="20%">Car<span class="red">*</span>:<td>
											<td width="80%">
<!------------------------------------------------------------------------------------------------------------------>

<select id="carSelection" onchange="selectCar()" disabled>
			
 			<?php
 			
 			$selected="";
 			
 			
 				
 			if(isset($cars) && count($cars)==1)
 			{
 				if($aptIsSelected)
	 			{
	 				$selected = "selected";
	 			}
	 			/*else
	 			{
	 				$selected = "";
	 			}*/
 			
 				echo "<option value='".$cars[0]->getCarId()."'".$selected.">Car #".$cars[0]->getCarId()."-->".$cars[0]->getModel()."</option>";
 				echo "<script>selectedCarIndex =" . $cars[0]->getCarId().";</script>" ;
 				
 			}
 			else if(isset($cars) && count($cars)>0)
 			{
 				echo "<option value='-1'></option>";
 				
 				foreach($cars as $car)
 				{
 					if($aptIsSelected && $car->getCarId()==$selectedAppointment->getCarId())
		 			{
		 				$selected = "selected";
		 			}
		 			else
		 			{
		 				$selected = "";
		 			}
 				
 					echo "<option value='".$car->getCarId()."'".$selected.">Car #".$car->getCarId()."-->".$car->getModel()."</option>";
 				}
 			}
 			?>

 			
			</select>



<!------------------------------------------------------------------------------------------------------------------>
											</td>
										</tr>
										<tr>
											<td width="20%">Procudure:<td>
											<td width="80%">
													<select id="procedureSelection" onchange="selectProcedure()" disabled>
													<option value="-1"></option>
							 						<?php
														
														if(isset($procedures))
														{
															foreach($procedures as $procedure)
															{
																echo "<option value=".$procedure->getProcedureId().">Task#".$procedure->getProcedureId()." - ".$procedure->getName()."</option>";
																//echo "<option value=".$procedure->getProcedureId().">".$procedure->getName()."</option>";
															}
														}
			 										
			 										?>
													</select>
													
													<input type="button" value="+" id="plus" name="plus" onclick="addTask()" disabled>
													<input type="button" value="-" id="minus" name="minus" onclick="removeTask()" disabled>
											</td>
										</tr>
										<tr>
											<td colspan="4">
												<table id="procedure_table">
													<tr>
														<th style="width:40%">Procedure</th>
														<th style="width:40%">Item</th>
														<th style="width:10%">Qty</th>
														<th style="width:10%">Mins</th>
													</tr>
													
													<tr><td width="100%" colspan="4" style="border:0px">
														<div id="procTable"><?php if($aptIsSelected){echo displayTable($proceduresByAppointment,$procedures,$allProceduresItems,$inventoryItems);}?></div>			
													</td></tr>							
																									
												</table>
											</td>
										</tr>
										<tr>
											<td colspan="5"><br>
											<table>
												<tr>
													<td>Total Estimate Time:</td><td><div id="estTime"><?php if($aptIsSelected){echo getEstTime($selectedAppointment->getTotalEstimateTime());}else{echo "N/A";}?></div></td>
													<td></td>
												</tr>
												<tr>
													<td class="right">Appointment Date<span class="red">*</span>: <br><div style="text-align:center">(yyyy-mm-dd)</div></td>
													<td><input type="text" value="<?php if($aptIsSelected){echo $selectedAppointment->getDate();}else{echo "";} ?>" id="appointmentDate" name="id="appointmentDate"" <?php if($aptIsSelected){echo "disabled";}else{echo "enabled";} ?>></td>
												</tr>
											</table>
											</td>
										</tr>
										<tr>
											<td colspan="5">
												<table>
													<tr>
														<td>Start Time<span class="red">*</span>:
															<select id="start_hour" disabled>

										 						<?php
										 						
											 						$selected="";
											 						
											 						if($aptIsSelected)
											 						{
											 							$myhour = floor(($selectedAppointment->getStartTime())/100);
											 						}
											 						
																	for ($x=9; $x<=21; $x++)
																    {
																    	if($aptIsSelected && $myhour==$x)
																    	{
																    		$selected="selected";
																    	}
																    	else
																    	{
																    		$selected="";
																    	}
																    
																	  echo "<option value='".$x."' ".$selected.">".$x."</option>";
																	}
										 						
										 						?>
										 													 					
															</select>
															<select id="start_min" disabled>
															<?php
										 						
											 						$selected="";
											 						
											 						if($aptIsSelected)
											 						{
											 							$myminute = ((($selectedAppointment->getStartTime())%100)/15);
											 						}
											 						
																	for ($x=0; $x<4; $x++)
																    {
																    	if($aptIsSelected && $myminute==$x)
																    	{
																    		$selected="selected";
																    	}
																    	else
																    	{
																    		$selected="";
																    	}
																    
																	  echo "<option value='".$x."' ".$selected.">".$minuteSlot[$x]."</option>";
																	}
										 						
										 						?>
															</select>
														</td>
														<td>End Time<span class="red">*</span>:
														<select id="end_hour" disabled>
										 						<?php
										 						
											 						$selected="";
											 						
											 						if($aptIsSelected)
											 						{
											 							$myhour = floor(($selectedAppointment->getEndTime())/100);
											 						}
											 						
																	for ($x=9; $x<=21; $x++)
																    {
																    	if($aptIsSelected && $myhour==$x)
																    	{
																    		$selected="selected";
																    	}
																    	else
																    	{
																    		$selected="";
																    	}
																    
																	  echo "<option value='".$x."' ".$selected.">".$x."</option>";
																	}
										 						
										 						?>
															</select>
															<span>:</span>
															<select id="end_min" disabled>
																<?php
										 						
											 						$selected="";
											 						
											 						if($aptIsSelected)
											 						{	
											 							$myminute = ((($selectedAppointment->getEndTime())%100)/15);
											 							
											 						}
											 						
																	for ($x=0; $x<4; $x++)
																    {
																    	if($aptIsSelected && $myminute==$x)
																    	{
																    		$selected="selected";
																    	}
																    	else
																    	{
																    		$selected="";
																    	}
																    
																	  echo "<option value='".$x."' ".$selected.">".$minuteSlot[$x]."</option>";
																	}
										 						
										 						?>
															</select>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table></div>
									
									
									
								</td>
							</tr>
							
							<tr>
								<td style="border:0px solid black;text-align:center;"> 
									<table style="border:2px solid black; ">
											Appointment(s) Taken:<br>
										<select id="aptSelection" style="width:200px; text-align:center;" <?php if(isset($appointments) && count($appointments)>0){echo "enabled";}else{echo "disabled";}?>>
										
										<?php if(isset($appointments) && count($appointments)>0){echo "<option style='text-align:center;' value='-1'>Appointment(s) found.</option>";}else{echo "<option style='text-align:center;' value='-1'>No appointment booked.</option>";}?>
										
										
											<?php
														
												if(isset($appointments))
												{
													foreach($appointments as $appointment)
													{
														echo "<option style='text-align:left;' value=".$appointment->getAppointmentId()." onclick='selectAppointment(".$appointment->getAppointmentId().")'>Appt#".$appointment->getAppointmentId()." - On ".$appointment->getDate()." @ ". floor(($appointment->getStartTime())/100).":".$minuteSlot[((($appointment->getStartTime())%100)/15)]." - ".floor(($appointment->getEndTime())/100).":".$minuteSlot[((($appointment->getEndTime())%100)/15)]."</option>";
													}
												}
	
			 								?>
			 								
					                    </select>
									</table>
								</td>
							</tr>
							
			</table>
		</td>
	
		<td style="border:0px solid black; width:60%; height:100%;">
		
		<table width="100%"  style="height:100%;">
		<tr><td>
			<table id="calendar_header_table">
				<tr>
					<td style="text-align:center; font-weight:bold; text-decoration: underline;" colspan="9">
						<br><?php echo date('F',$monday); ?><br><br>
					</td>	
				</tr>
			
				<tr>
				<td ><input type="button" id="prevWeekBtn" onclick="lastWeek()" name="prevWeekBtn" value="Prev" >
				<input type="button" id="nextWeekBtn" onclick="nextWeek()" name="nextWeekBtn" value="Next" ></td>
				<th><?php echo date("D",$monday)."<br>".date("d",$monday); ?></th>
				<th><?php echo date("D",$tuesday)."<br> ".date("d",$tuesday); ?></th>
				<th><?php echo date("D",$wednesday)."<br> ".date("d",$wednesday); ?></th>
				<th><?php echo date("D",$thursday)."<br> ".date("d",$thursday); ?></th>
				<th><?php echo date("D",$friday)."<br> ".date("d",$friday); ?></th>
				<th><?php echo date("D",$saturday)."<br> ".date("d",$saturday); ?></th>
				<th><?php echo date("D",$sunday)."<br> ".date("d",$sunday); ?></th>
				</tr>
			</table>
		</td></tr>
		
		
			<tr><td><div style="overflow:hidden; overflow-y:auto; height:400px;">
			<table id="calendar_table" style="height:100%; width:100%;">
				<?php
				
				$lastAppId="";
					
					echo "<tr>";
								
					for($x=0; $x<=$numbOfDay; $x++)
					{
						if($x==0)
						{	
							$tempCount=0;
							
							echo "<td width='14%' id='timeCol'><table class='subTable'>";
							
							for($y=0; $y<$slots; $y++)
							{

								if($tempCount==4)
								{
									$openingAt++;
									$tempCount=0;
								}
								
								echo "<tr><td class='timeColCell'>" . $openingAt . ":" . $minuteSlot[$tempCount] . "</td></tr>";
								
								$timeInInteger = ($openingAt * 100) + (15 * $tempCount); 
								array_push($timeArrayInInteger,$timeInInteger);
								
								$tempCount++;
								
							}
							
							echo "</table></td>";	
						}
						else  //From Monday To Sunday Column
						{
	
							echo "<td><table class='subTable'>";
							
							
							
							for($cell=0; $cell<count($timeArrayInInteger); $cell++)
							{
								$thisCellCrossesApp = false;
								$currentAppId="";

								if(isset($allAppointments))
								{	
									foreach($allAppointments as $appointment)
									{
										if($appointment->getDate()==$dateOfThisWeek[$x-1])
										{
										
											if($timeArrayInInteger[$cell] == $appointment->getStartTime() ||  $timeArrayInInteger[$cell] > $appointment->getStartTime() &&  $timeArrayInInteger[$cell] < $appointment->getEndTime() ||  $timeArrayInInteger[$cell] == ($appointment->getEndTime()-15))
											{
												$thisCellCrossesApp = true;	
	
												$currentAppId=$appointment->getAppointmentId();	
												$currentClientId=$appointment->getProfileId();	
												
												if($lastAppId!="" && $lastAppId != $appointment->getAppointmentId())
												{
													$currentColor++;
												}
											}
										}				
									}
	
									if($thisCellCrossesApp == true)
									{
										$lastAppId = $currentAppId;
										echo "<tr><td class='cell' onclick='selectAppointment(".$currentAppId.")' style='min-width:20px; max-width:20px; background:".$colorList[$currentColor%5].";'>".$currentAppId."(".$currentClientId.")</td></tr>";
									}
									
									else if($thisCellCrossesApp == false)
									{
										echo "<tr><td class='cell' style='min-width:20px; max-width:20px;'>"."-"."</td></tr>";
									}
									
									
								
								}
								else
								{			
									echo "<tr><td class='cell'>"."-"."</td></tr>";
								}
								
							}
								
							echo "</table></td>";
						}
					}
				
					echo "</tr>";
				?>
			</table></div>
			</td></tr>
			
			<tr><td class="right"><br><input id="endAppointmentBtn" type="button" value="End Appointment" onclick="endAppointment()" <?php if(isset($aptIsSelected) && $aptIsSelected!= ""){echo "enabled";}else{echo "disabled";}?>></td></tr>
		
		</table>
		</td>
		
	
	
	</tr>
	
	</table>
</form>					
<!------------------------------------------------------------------------>
			
</td>
</tr>